package com.web.dao;

import com.web.controller.web.WebSysLogController;
import com.web.entity.OrderRecordForPlatform;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class OrderRecordForPlatformSqlProvider {

    public String insertSelective(OrderRecordForPlatform record) {
        BEGIN();
        INSERT_INTO("t_order_record_for_platform");
        
        if (record.getOrderNum() != null) {
            VALUES("order_num", "#{orderNum,jdbcType=VARCHAR}");
        }
        
        if (record.getConsumer() != null) {
            VALUES("consumer", "#{consumer,jdbcType=VARCHAR}");
        }
        
        if (record.getMerchant() != null) {
            VALUES("merchant", "#{merchant,jdbcType=VARCHAR}");
        }
        
        if (record.getStore() != null) {
            VALUES("store", "#{store,jdbcType=VARCHAR}");
        }
        
        if (record.getConsumerPhone() != null) {
            VALUES("consumer_phone", "#{consumerPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getMerchantPhone() != null) {
            VALUES("merchant_phone", "#{merchantPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreId() != null) {
            VALUES("store_id", "#{storeId,jdbcType=BIGINT}");
        }
        
        if (record.getConsumeBal() != null) {
            VALUES("consume_bal", "#{consumeBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTipBal() != null) {
            VALUES("tip_bal", "#{tipBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTotalBal() != null) {
            VALUES("total_bal", "#{totalBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTransferProfit() != null) {
            VALUES("transfer_profit", "#{transferProfit,jdbcType=DECIMAL}");
        }
        
        if (record.getTransferBal() != null) {
            VALUES("transfer_bal", "#{transferBal,jdbcType=DECIMAL}");
        }
        
        if (record.getMerchantIncome() != null) {
            VALUES("merchant_income", "#{merchantIncome,jdbcType=DECIMAL}");
        }
        
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(OrderRecordForPlatform record) {
        BEGIN();
        UPDATE("t_order_record_for_platform");
        
        if (record.getOrderNum() != null) {
            SET("order_num = #{orderNum,jdbcType=VARCHAR}");
        }
        
        if (record.getConsumer() != null) {
            SET("consumer = #{consumer,jdbcType=VARCHAR}");
        }
        
        if (record.getMerchant() != null) {
            SET("merchant = #{merchant,jdbcType=VARCHAR}");
        }
        
        if (record.getStore() != null) {
            SET("store = #{store,jdbcType=VARCHAR}");
        }
        
        if (record.getConsumerPhone() != null) {
            SET("consumer_phone = #{consumerPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getMerchantPhone() != null) {
            SET("merchant_phone = #{merchantPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getStoreId() != null) {
            SET("store_id = #{storeId,jdbcType=BIGINT}");
        }
        
        if (record.getConsumeBal() != null) {
            SET("consume_bal = #{consumeBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTipBal() != null) {
            SET("tip_bal = #{tipBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTotalBal() != null) {
            SET("total_bal = #{totalBal,jdbcType=DECIMAL}");
        }
        
        if (record.getTransferProfit() != null) {
            SET("transfer_profit = #{transferProfit,jdbcType=DECIMAL}");
        }
        
        if (record.getTransferBal() != null) {
            SET("transfer_bal = #{transferBal,jdbcType=DECIMAL}");
        }
        
        if (record.getMerchantIncome() != null) {
            SET("merchant_income = #{merchantIncome,jdbcType=DECIMAL}");
        }
        
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }



    public String selectAllOrderLogs(WebSysLogController.OrderLogColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("order_num");
        SELECT("consumer");
        SELECT("merchant");
        SELECT("store");
        SELECT("consumer_phone");
        SELECT("merchant_phone");
        SELECT("store_id");
        SELECT("consume_bal");
        SELECT("tip_bal");
        SELECT("total_bal");
        SELECT("transfer_profit");
        SELECT("transfer_bal");
        SELECT("merchant_income");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_order_record_for_platform");

        if (record.getOrderNum() != null && !"".equals(record.getOrderNum())) {
            WHERE("order_num = #{orderNum,jdbcType=VARCHAR}");
        }

        if (record.getConsumer() != null && !"".equals(record.getConsumer())) {
            WHERE("consumer like #{consumer,jdbcType=VARCHAR}");
        }

        if (record.getMerchant() != null && !"".equals(record.getMerchant())) {
            WHERE("merchant like #{merchant,jdbcType=VARCHAR}");
        }

        if (record.getStore() != null && !"".equals(record.getStore())) {
            WHERE("store like #{store,jdbcType=INTEGER}");
        }
        if (record.getConsumerPhone() != null && !"".equals(record.getConsumerPhone())) {
            WHERE("consumer_phone like #{consumerPhone,jdbcType=VARCHAR}");
        }

        if (record.getMerchantPhone() != null && !"".equals(record.getMerchantPhone())) {
            WHERE("merchant_phone like #{merchantPhone,jdbcType=INTEGER}");
        }

        if(record.getBegin_createTime()!=null){
            WHERE("create_time >= #{begin_createTime,jdbcType=TIMESTAMP}");
        }
        if(record.getEnd_createTime()!=null){
            WHERE("create_time <= #{end_createTime,jdbcType=TIMESTAMP}");
        }
        if(record.getBegin_modifyTime()!=null){
            WHERE("modify_time >= #{begin_modifyTime,jdbcType=TIMESTAMP}");
        }
        if(record.getEnd_modifyTime()!=null){
            WHERE("modify_time >= #{end_modifyTime,jdbcType=TIMESTAMP}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }

}